package com.yulintu.utils;

import net.contentobjects.jnotify.JNotify;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @author caomin
 * @date 2017/10/27
 * @说明 文件监控
 */
@Component
public class FileNotifyUtils  implements CommandLineRunner {

    @Value("${fileupload.path}")
    private String filePath;

    @Autowired
    Filejnotify filejnotify;


    public void notifyFile() throws Exception {
        int mask = JNotify.FILE_ANY;
        boolean watchSubtree = true;
        JNotify.addWatch(filePath, mask, watchSubtree,filejnotify);
    /*    while (true){
            Thread.sleep(5000);
        }*/
    }

    @Override
    public void run(String... args) throws Exception {
        this.notifyFile();
    }
}
